// pages/search/search.js
import {
  post
} from '../../utils/http'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    txt: '',
    datalist: [],
    historylist: wx.getStorageSync('historylist') || [],
    isShowHistory: true
  },

  async handleSearch() {
    let historylist = wx.getStorageSync('historylist') || [];
    historylist.push(this.data.txt)
    wx.setStorageSync('historylist', [...new Set(historylist)])
    let rs = await post('/index.php/trade/get_search_list', {
      keyword: this.data.txt
    })
    console.log(rs)
    this.setData({
      isShowHistory: false,
      datalist: rs.data
    })
  },

  handleClick(e) {
    console.log(e)
    this.setData({
      txt: e.target.dataset.keyword
    })
    this.handleSearch();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  goDetail(e) {
    console.log(e.currentTarget.dataset.item)
    let {id,address} = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: `/pages/deatil/detail?id=${id}&address=${address}`,
    })
  }

})